<!doctype html>
<html>
  <head>
    <title>Notifications: Check that showNotifications rejects if actions is set incorrectly.</title>
    <script src="../resources/testharness.js"></script>
    <script src="../resources/testharnessreport.js"></script>
    <script src="../serviceworker/resources/test-helpers.js"></script>
    <script src="resources/test-helpers.js"></script>
  </head>
  <body>
    <script>
      // Tests that serviceWorkerRegistration.showNotification throws a
      // TypeError if NotificationOptions.actions is set incorrectly.
      var script = 'instrumentation-service-worker.js';

      testRunner.setPermission('notifications', 'granted', location.origin, location.origin);

      async_test(function(test) {
          var scope = 'resources/scope/' + location.pathname + "/noaction";

          getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) {
              assert_inherits(workerInfo.registration, 'showNotification', 'showNotification() must be exposed.');

              workerInfo.registration.showNotification('Title', {
                  actions: [{ title: "Foo" }]
              }).then(unreached_fulfillment(test)).catch(function(error) {
                  assert_equals(error.name, 'TypeError');
                  assert_equals(error.message, "Failed to execute 'showNotification' on 'ServiceWorkerRegistration': Failed to read the 'actions' property from 'NotificationOptions': Failed to read the 'action' property from 'NotificationAction': Failed to read the 'action' property from 'NotificationAction': Required member is undefined.");
                  test.done();
              });
          }).catch(unreached_rejection(test));

      }, 'showNotification() must reject if a NotificationAction has no action.');

      async_test(function(test) {
          var scope = 'resources/scope/' + location.pathname + "/notitle";

          getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) {
              assert_inherits(workerInfo.registration, 'showNotification', 'showNotification() must be exposed.');

              workerInfo.registration.showNotification('Title', {
                  actions: [{ action: "foo" }]
              }).then(unreached_fulfillment(test)).catch(function(error) {
                  assert_equals(error.name, 'TypeError');
                  assert_equals(error.message, "Failed to execute 'showNotification' on 'ServiceWorkerRegistration': Failed to read the 'actions' property from 'NotificationOptions': Failed to read the 'title' property from 'NotificationAction': Failed to read the 'title' property from 'NotificationAction': Required member is undefined.");
                  test.done();
              });
          }).catch(unreached_rejection(test));

      }, 'showNotification() must reject if a NotificationAction has no title.');
    </script>
  </body>
</html>
